package top.resty.erp.dao;

import org.apache.ibatis.annotations.*;
import top.resty.erp.domain.Products;
import top.resty.erp.domain.Storage;

import java.util.List;

/**
 * <pre>
 *
 * </pre>
 *
 * @author : resty
 * @date : 2021年03月31 16:44
 */
@Mapper
public interface IStorage {
	
	/**
	 * =========================查询部分信息==============================
	 **/
	
	@Select("select distinct standard from tb_storage where type = #{name}")
	public List<String> getStandardsName(String name);
	
	
	@Select("select distinct type from tb_storage where variety = #{name}")
	public List<String> getTypesName(String name);
	
	
	
	@Select("select distinct variety from tb_storage")
	public List<String> findByVarieties();
	
	@Select({"<script>",
				"select * from tb_storage where 1=1 ",
				"<if test = 'storage.variety != null and storage.variety !=\"\"'>and variety = #{storage.variety}</if>",
				"<if test = 'storage.type != null and storage.type !=\"\"'>and type = #{storage.type}</if>",
				"<if test = 'storage.standard != null and storage.standard !=\"\"'>and standard = #{storage.standard}</if>",
			"</script>"
	})
	public List<Storage> findStorageByCondition(@Param("storage") Storage storage);
	
	
	/**
	 * =========================添加及修改==============================
	 **/
	
	@Update("update tb_storage set count = #{arg0} where id = #{arg1}")
	public int updateCount(Integer value, Integer id);
	
	/**
	 * 从数据库中拿到对应的库存数据
	 */
	@Select("select * from tb_storage where variety = #{products.varietyName} and type = #{products.typeName} and " + "standard = #{products.standard}")
	public Storage findStorageByProducts(@Param("products") Products products);
	
	@Insert("insert into tb_storage values(null,#{variety},#{type},#{standard},#{count})")
	public int saveStorage(Storage storage);
	
	@Select("select * from tb_storage where id = #{id}")
	public Storage findById(Integer id);
	
	@Select("select * from tb_storage")
	public List<Storage> findAll();
	
}
